import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

import Layout from '@/layout'

// 不需要动态判断权限的路由, 如登录页、404、等通用页面===================================================
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  { // 用户登录
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  { // 企业信息
    path: '/corporation',
    component: () => import('@/views/login/corporation'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  }

  // {
  //   path: '/',
  //   component: Layout,
  //   // redirect: '/dashboard',
  //   redirect: '/system',
  //   name: 'Root_home',
  //   children: [
  //     {
  //       path: 'dashboard',
  //       component: () => import('@/views/dashboard/index'),
  //       name: 'Dashboard',
  //       meta: { title: 'dashboard', icon: 'icon-shouye', affix: false } // affix, 固定在tagview中
  //     }
  //   ]
  // }
]

// 需求动态判断权限并通过 addRoutes 动态添加的页面===================================================
export function getMenu(perms) {
  let asyncRoutes2 = []
  if (perms === undefined || perms === null || perms.length <= 0) {
    return asyncRoutes2
  }
  asyncRoutes2 = [
    {
      path: '/basics',
      component: Layout,
      redirect: '/basics/info',
      name: 'Basics',
      hidden: true,
      children: [
        {
          path: 'info',
          component: () => import('@/views/basics/info'),
          name: 'InfoBasics',
          hidden: true,
          meta: { title: '基础信息', icon: 'icon-tongji', affix: false }
        }
      ]
    },
    {
      path: '/home',
      component: () => import('@/views/home'),
      name: 'Dash',
      // hidden: !perms.includes('8000001'),
    },
    {
      path: '/',
      component: Layout,
      redirect: '/video',
      name: 'Root_sta',
      hidden: !perms.includes('8000001'),
      children: [
        {
          path: 'home',
          component: () => import('@/views/home'),
          // component: () => import('@/views/workorder/workorderboard'),
          name: 'Home',
          hidden: !perms.includes('8000001'),
          meta: { title: '首页', icon: 'icon-shouye', affix: false, bread: 'icon-gongdan' }
        }
      ]
    },


    {
      path: '/video',
      component: Layout,
      redirect: '/video/videomonitor',
      name: 'Video',
      hidden: !perms.includes('8000005'),
      meta: { title: '视频中心', icon: 'icon-shipin4' },
      children: [
        {
          path: 'videomonitor',
          component: () => import('@/views/video/videomonitor'),
          name: 'VideoMonitor',
          hidden: !perms.includes('800000501'),
          meta: { title: '视频监控', icon: 'icon-dian', bread: 'icon-shexiangtou' }
        },
        {
          path: 'keyrotation',
          component: () => import('@/views/video/keyrotation'),
          name: 'keyrotation',
          hidden: false,
          meta: { title: '重点轮播', icon: 'icon-dian', bread: 'icon-shexiangtou' }
        },
        {
          path: 'videoplayback',
          component: () => import('@/views/video/videoplayback'),
          name: 'VideoPlayback',
          hidden: !perms.includes('800000502'),
          meta: { title: '历史回放', icon: 'icon-dian', bread: 'icon-shipin5' }
        },
        {
          path: 'videodownload',
          component: () => import('@/views/video/videodownload'),
          name: 'VideoDownload',
          hidden: !perms.includes('800000503'),
          meta: { title: '下载中心', icon: 'icon-dian', bread: 'icon-download-fill' }
        }
      ]
    },
    {
      path: '/cruising',
      component: Layout,
      redirect: '/cruising/cruvideo',
      name: 'Cruising',
      hidden: !perms.includes('8000008'),
      meta: { title: '巡察中心', icon: 'icon-xunjianguanli' },
      children: [
        {
          path: 'cruvideo',
          component: () => import('@/views/cruising/cruvideo'),
          name: 'Cruvideo',
          hidden: !perms.includes('800000801'),
          meta: { title: '视频巡察', icon: 'icon-dian', bread: 'icon-dengdaixuncha' }
        },
        {
          path: 'crupicture',
          component: () => import('@/views/cruising/crupicture'),
          name: 'Crupicture',
          hidden: !perms.includes('800000802'),
          meta: { title: '图片巡察', icon: 'icon-dian', bread: 'icon-picture' }
        },
        {
          path: 'crutask',
          component: () => import('@/views/cruising/crutask'),
          name: 'Crutask',
          hidden: !perms.includes('800000803'),
          meta: { title: '任务巡察', icon: 'icon-dian', bread: 'icon-renwubaogongzuo' }
        },
        {
          path: 'crurecord',
          component: () => import('@/views/cruising/crurecord'),
          name: 'Crurecord',
          hidden: !perms.includes('800000804'),
          meta: { title: '巡察记录', icon: 'icon-dian', bread: 'icon-gongdan1' }
        },
        {
          path: 'cruanalysis',
          component: () => import('@/views/cruising/cruanalysis'),
          name: 'Cruanalysis',
          hidden: !perms.includes('800000805'),
          meta: { title: '巡察分析', icon: 'icon-dian', bread: 'icon-fenxi1' }
        },
        {
          path: 'crusetting',
          component: () => import('@/views/cruising/crusetting'),
          name: 'Crusetting',
          hidden: !perms.includes('800000806'),
          meta: { title: '考核设置', icon: 'icon-dian', bread: 'icon-jiangbei' }
        },
        {
          path: 'personnel',
          component: () => import('@/views/cruising/personnel'),
          name: 'Personnel',
          meta: { title: '人员检测', icon: 'icon-dian', bread: 'icon-jiangbei' }
        }
      ]
    },
    {
      path: '/workorder',
      component: Layout,
      redirect: '/workorder/workorderself',
      name: 'Workorder',
      hidden: !perms.includes('8000007'),
      meta: { title: '工单管理', icon: 'icon-gongdanguanli' },
      children: [
        {
          path: 'workorderself',
          component: () => import('@/views/workorder/workorderself'),
          name: 'Workorderself',
          hidden: !perms.includes('800000701'),
          meta: { title: '我的工单', icon: 'icon-dian', bread: 'icon-jiaose' }
        },
        {
          path: 'workorderboard',
          component: () => import('@/views/workorder/workorderboard'),
          name: 'workorderboard',
          hidden: !perms.includes('800000702'),
          meta: { title: '工单看板', icon: 'icon-dian', bread: 'icon-B' }
        },
      {
        path: 'workorderInfo',
        component: () => import('@/views/workorder/workorderInfo'),
        name: 'workorderInfo',
        hidden: true,
        meta: { title: '工单信息', icon: 'icon-dian' },
      }
      ]
    },
    {
      path: '/branch',
      component: Layout,
      redirect: '/branch/branchsetting',
      name: 'Branch',
      hidden: !perms.includes('8000006'),
      meta: { title: '网点管理', icon: 'icon-renwu2' },
      children: [
        {
          path: 'branchsetting',
          component: () => import('@/views/branch/branchsetting'),
          name: 'Branchsetting',
          hidden: !perms.includes('800000601'),
          meta: { title: '网点设置', icon: 'icon-dian', bread: 'icon-line' }
        },
        // {
        //   path: 'branchmap',
        //   component: () => import('@/views/branch/branchmap'),
        //   name: 'Branchmap',
        //   meta: { title: '地图管理', icon: 'icon-dian', bread: 'icon-icon-test' }
        // },
        {
          path: 'branchdevice',
          component: () => import('@/views/branch/branchdevice'),
          name: 'BranchDevice',
          hidden: !perms.includes('800000602'),
          meta: { title: '设备管理', icon: 'icon-dian', bread: 'icon-shipin2' }
        }
      ]
    },
    {
      path: '/permission',
      component: Layout,
      redirect: '/permission/permissionuser',
      name: 'Permission',
      hidden: !perms.includes('8000009'),
      meta: { title: '权限管理', icon: 'icon-quanxianguanli1' },
      children: [
        {
          path: 'permissionuser',
          component: () => import('@/views/permission/permissionuser'),
          name: 'Permissionuser',
          hidden: !perms.includes('800000901'),
          meta: { title: '用户管理', icon: 'icon-dian', bread: 'icon-lunkuohua2_yonghu' }
        },
        {
          path: 'permissionrole',
          component: () => import('@/views/permission/permissionrole'),
          name: 'Permissionrole',
          hidden: !perms.includes('800000902'),
          meta: { title: '角色管理', icon: 'icon-dian', bread: 'icon-shujujiaosequanxianguanli' }
        },
        {
          path: 'permissionresource',
          component: () => import('@/views/permission/permissionresource'),
          name: 'Permissionresource',
          hidden: !perms.includes('800000904'),
          meta: { title: '资源组管理', icon: 'icon-dian', bread: 'icon-louceng0' }
        },
        // {
        //   path: 'permissionmenu',
        //   component: () => import('@/views/permission/permissionmenu'),
        //   name: 'Permissionmenu',
        //   meta: { title: '菜单管理', icon: 'icon-dian', bread: 'icon-louceng0' }
        // },
        {
          path: 'permissioncheck',
          component: () => import('@/views/permission/permissioncheck'),
          name: 'Permissioncheck',
          hidden: !perms.includes('800000903'),
          meta: { title: '审批中心', icon: 'icon-dian', bread: 'icon-shenhe2' }
        },
      ]
    },

    // 404 page must be placed at the end !!!
    { path: '*', redirect: '/404', hidden: true }
  ]
  // asyncRoutes2 = [
  //   {
  //     path: '/system',
  //     component: Layout,
  //     redirect: '/system/account',
  //     name: 'System',
  //     hidden: !perms.includes('2'),
  //     meta: {
  //       title: '系统设置',
  //       icon: 'icon-xitongshezhi'
  //     },
  //     children: [
  //       {
  //         path: 'account',
  //         component: () => import('@/views/system/account'),
  //         name: 'AccountSystem',
  //         hidden: !perms.includes('5'),
  //         meta: {
  //           title: '账户管理',
  //           icon: 'icon-weibiaoti5'
  //         }
  //       },
  //       {
  //         path: 'role',
  //         component: () => import('@/views/system/role'),
  //         name: 'RoleSystem',
  //         hidden: !perms.includes('6'),
  //         meta: {
  //           title: '角色管理',
  //           icon: 'icon-huabanfuben'
  //         }
  //       },
  //       {
  //         path: 'module',
  //         component: () => import('@/views/system/module'),
  //         name: 'ModuleSystem',
  //         hidden: !perms.includes('7'),
  //         meta: {
  //           title: '模块管理',
  //           icon: 'icon-mokuaiguanli'
  //         }
  //       }
  //     ]
  //   },
  //   {
  //     path: '/client',
  //     component: Layout,
  //     redirect: '/client/clientlist',
  //     name: 'Client',
  //     hidden: !perms.includes('3'),
  //     meta: {
  //       title: '用户管理',
  //       icon: 'icon-yonghu'
  //     },
  //     children: [
  //       {
  //         path: 'clientlist',
  //         component: () => import('@/views/client/clientlist'),
  //         name: 'ListClient',
  //         hidden: !perms.includes('8'),
  //         meta: {
  //           title: '用户列表',
  //           icon: 'icon-ico-'
  //         }
  //       },
  //       {
  //         path: 'allocation',
  //         component: () => import('@/views/client/allocation'),
  //         name: 'AllocationClient',
  //         hidden: !perms.includes('9'),
  //         meta: {
  //           title: '资源分配',
  //           icon: 'icon-shujuku_'
  //         }
  //       }
  //     ]
  //   },
  //   {
  //     path: '/platform',
  //     component: Layout,
  //     redirect: '/platform/platformlist',
  //     name: 'Platform',
  //     hidden: !perms.includes('4'),
  //     meta: {
  //       title: '平台管理',
  //       icon: 'icon-pingtaiguanli'
  //     },
  //     children: [
  //       {
  //         path: 'platformlist',
  //         component: () => import('@/views/platform/platformlist'),
  //         name: 'ListPlatform',
  //         hidden: !perms.includes('10'),
  //         meta: {
  //           title: '平台列表',
  //           icon: 'icon-liebiao'
  //         }
  //       }
  //       // {
  //       //   path: 'platformlist2',
  //       //   component: () => import('@/views/platform/platformlist'),
  //       //   name: 'ListPlatform2',
  //       //   meta: {
  //       //     title: '平台列表2',
  //       //   }
  //       // },
  //     ]
  //   },

  //   // 404 page must be placed at the end !!!
  //   { path: '*', redirect: '/404', hidden: true }
  // ]
  return asyncRoutes2
}
// 需求动态判断权限并通过 addRoutes 动态添加的页面,,枚举出来===================================================
export const asyncRoutes = [
  {
    path: '/basics',
    component: Layout,
    redirect: '/basics/info',
    name: 'Basics',
    hidden: true,
    children: [
      {
        path: 'info',
        component: () => import('@/views/basics/info'),
        name: 'InfoBasics',
        hidden: true,
        meta: { title: '基础信息', icon: 'icon-tongji', affix: false }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    name: 'Root_sta',
    children: [
      {
        path: 'home',
        // component: () => import('@/views/home'),
        component: () => import('@/views/workorder/workorderboard'),
        name: 'Home',
        meta: { title: '首页', icon: 'icon-shouye', affix: false, bread: 'icon-gongdan' }
      }
    ]
  },
  {
    path: '/video',
    component: Layout,
    redirect: '/video/videomonitor',
    name: 'Video',
    meta: { title: '视频中心', icon: 'icon-shipin4' },
    children: [
      {
        path: 'videomonitor',
        component: () => import('@/views/video/videomonitor'),
        name: 'VideoMonitor',
        meta: { title: '视频监控', icon: 'icon-dian', bread: 'icon-shexiangtou' }
      },
      {
        path: 'videoplayback',
        component: () => import('@/views/video/videoplayback'),
        name: 'VideoPlayback',
        meta: { title: '历史回放', icon: 'icon-dian', bread: 'icon-shipin5' }
      },
      {
        path: 'videodownload',
        component: () => import('@/views/video/videodownload'),
        name: 'VideoDownload',
        meta: { title: '下载中心', icon: 'icon-dian', bread: 'icon-download-fill' }
      }
    ]
  },
  {
    path: '/cruising',
    component: Layout,
    redirect: '/cruising/cruvideo',
    name: 'Cruising',
    meta: { title: '巡察中心', icon: 'icon-xunjianguanli' },
    children: [
      {
        path: 'cruvideo',
        component: () => import('@/views/cruising/cruvideo'),
        name: 'Cruvideo',
        meta: { title: '视频巡察', icon: 'icon-dian', bread: 'icon-dengdaixuncha' }
      },
      {
        path: 'crupicture',
        component: () => import('@/views/cruising/crupicture'),
        name: 'Crupicture',
        meta: { title: '图片巡察', icon: 'icon-dian', bread: 'icon-picture' }
      },
      {
        path: 'crutask',
        component: () => import('@/views/cruising/crutask'),
        name: 'Crutask',
        meta: { title: '任务巡察', icon: 'icon-dian', bread: 'icon-renwubaogongzuo' }
      },
      {
        path: 'crurecord',
        component: () => import('@/views/cruising/crurecord'),
        name: 'Crurecord',
        meta: { title: '巡察记录', icon: 'icon-dian', bread: 'icon-gongdan1' }
      },
      {
        path: 'cruanalysis',
        component: () => import('@/views/cruising/cruanalysis'),
        name: 'Cruanalysis',
        meta: { title: '巡察分析', icon: 'icon-dian', bread: 'icon-fenxi1' }
      },
      {
        path: 'crusetting',
        component: () => import('@/views/cruising/crusetting'),
        name: 'Crusetting',
        meta: { title: '考核设置', icon: 'icon-dian', bread: 'icon-jiangbei' }
      },
    ]
  },
  {
    path: '/workorder',
    component: Layout,
    redirect: '/workorder/workorderself',
    name: 'Workorder',
    meta: { title: '工单管理', icon: 'icon-gongdanguanli' },
    children: [
      {
        path: 'workorderself',
        component: () => import('@/views/workorder/workorderself'),
        name: 'Workorderself',
        meta: { title: '我的工单', icon: 'icon-dian', bread: 'icon-jiaose' }
      },
      {
        path: 'workorderboard',
        component: () => import('@/views/workorder/workorderboard'),
        name: 'workorderboard',
        meta: { title: '工单看板', icon: 'icon-dian', bread: 'icon-B' }
      },
	  {
	    path: 'workorderInfo',
	    component: () => import('@/views/workorder/workorderInfo'),
	    name: 'workorderInfo',
	    meta: { title: '工单信息', icon: 'icon-dian' },
			hidden: true
	  }
    ]
  },
  {
    path: '/branch',
    component: Layout,
    redirect: '/branch/branchsetting',
    name: 'Branch',
    meta: { title: '网点管理', icon: 'icon-renwu2' },
    children: [
      {
        path: 'branchsetting',
        component: () => import('@/views/branch/branchsetting'),
        name: 'Branchsetting',
        meta: { title: '网点设置', icon: 'icon-dian', bread: 'icon-line' }
      },
      // {
      //   path: 'branchmap',
      //   component: () => import('@/views/branch/branchmap'),
      //   name: 'Branchmap',
      //   meta: { title: '地图管理', icon: 'icon-dian', bread: 'icon-icon-test' }
      // },
      {
        path: 'branchdevice',
        component: () => import('@/views/branch/branchdevice'),
        name: 'BranchDevice',
        meta: { title: '设备管理', icon: 'icon-dian', bread: 'icon-shipin2' }
      }
    ]
  },
  {
    path: '/permission',
    component: Layout,
    redirect: '/permission/permissionuser',
    name: 'Permission',
    meta: { title: '权限管理', icon: 'icon-quanxianguanli1' },
    children: [
      {
        path: 'permissionuser',
        component: () => import('@/views/permission/permissionuser'),
        name: 'Permissionuser',
        meta: { title: '用户管理', icon: 'icon-dian', bread: 'icon-lunkuohua2_yonghu' }
      },
      {
        path: 'permissionrole',
        component: () => import('@/views/permission/permissionrole'),
        name: 'Permissionuser',
        meta: { title: '角色管理', icon: 'icon-dian', bread: 'icon-shujujiaosequanxianguanli' }
      },
      {
        path: 'permissionresource',
        component: () => import('@/views/permission/permissionresource'),
        name: 'Permissionresource',
        meta: { title: '资源组管理', icon: 'icon-dian', bread: 'icon-louceng0' }
      },
      // {
      //   path: 'permissionmenu',
      //   component: () => import('@/views/permission/permissionmenu'),
      //   name: 'Permissionmenu',
      //   meta: { title: '菜单管理', icon: 'icon-dian', bread: 'icon-louceng0' }
      // },
      {
        path: 'permissioncheck',
        component: () => import('@/views/permission/permissioncheck'),
        name: 'Permissioncheck',
        meta: { title: '审批中心', icon: 'icon-dian', bread: 'icon-shenhe2' }
      },
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
